package com.bw.jtp.app.udf;

import ch.hsr.geohash.GeoHash;
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDF;

@Description(
        name = "convert_g",
        value = "_FUNC_(latitude, longitude, precision) - returns a geohash code"
)
public class ConvertGeoHash extends UDF {
    public String evaluate(double latitude,double longitude,int precision){
        GeoHash geoHash = GeoHash.withCharacterPrecision(latitude, longitude, precision);
        return geoHash.toBase32();

    }


    public static void main(String[] args) {
        System.out.println(
                new ConvertGeoHash().evaluate(35.46847397820407, 119.36278007513695, 6)
        );
    }
}
